﻿

namespace Jhong.FunMVC
{
    using System.Text;


    internal static class StringBuilderExtension
    {
        public static int IndexOf(this StringBuilder sb, string input)
        {
            var arr = input.ToCharArray();
            bool pass;
            var seek = 0;
            while (seek < sb.Length - arr.Length)
            {
                pass = true;
                for (int i = 0; i < arr.Length; i++)
                {
                    if (arr[i] != sb[seek + i]) pass = false;
                }
                if (pass) return seek;
                seek++;
            }
            return -1;
        }

        public static StringBuilder TrimEnd(this StringBuilder sb, string trimStr)
        {
            if (sb.Length < trimStr.Length) return sb;
            bool isTrim = true;
            for (int i = 0; i < trimStr.Length; i++)
            {
                if (sb[sb.Length - trimStr.Length + i] != trimStr[i]) isTrim = false;
            }
            if (isTrim) sb.Remove(sb.Length - trimStr.Length, trimStr.Length);
            return sb;
        }

    }
}
